#!/bin/bash

# 所需要的环境检查

# 检查是否安装 git
echo -e "\n>>> check git"
if [[ $(which git | wc -l) -eq 0 ]]
then
    echo "git ===> installing"

    yum install -y git

else
    echo "git ===> ok"
fi
git --version

# 检查是否安装 Docker
echo -e "\n>>> check docker"
if [[ $(which docker | wc -l) -eq 0 ]]
then
    echo "docker ===> installing"

    sudo curl -sSL https://get.docker.com | sh && systemctl start docker && systemctl enable docker

    # 配置阿里镜像源
    sudo mkdir -p /etc/docker
    sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://jdgbbr9w.mirror.aliyuncs.com"],
"log-driver":"json-file",
"log-opts": {"max-size":"100m", "max-file":"5"}
}
EOF
    sudo systemctl daemon-reload
    sudo systemctl restart docker

else
    echo "docker ===> ok"
fi
docker -v

# 检查是否安装 Docker-compose
echo -e "\n>>> check docker-compose"
if [[ $(which docker-compose | wc -l) -eq 0 ]]
then
    echo "docker-compose ===> installing"

    sudo curl -L "https://github.com/docker/compose/releases/download/1.28.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
    sudo chmod +x /usr/local/bin/docker-compose

    # 如上面方法遇到网络问题，则可以选择下面方法安装
    #yum -y install epel-release && \
    #yum -y install python-pip && \
    #pip install --upgrade pip && \
    #pip install -i https://pypi.tuna.tsinghua.edu.cn/simple docker-compose==1.24.1

else
    echo "docker-compose ===> ok"
fi
docker-compose -v
